home *** CD-ROM | disk | FTP | other *** search
- PROGRAM ShowEGA(input,output,picfile);
-
- { Copyright (c) 1987, Ciarcia's Circuit Cellar }
- { All Rights Reserved }
-
- { Version 1.01 May 12, 1987 }
- { Fixed SendEGA so it would work with more types }
- { of EGA boards. kwd }
-
- { shows image on EGA using histogram "color" assignment }
-
- {$U- control-break checking during execution }
- {$C- control-break checking during I/O operations }
- {$R- array range checking }
-
- {$Ideclares.p declarations }
- {$Ihexutil.p hex utilities }
- {$Iserial.p serial interface code }
- {$Ipictures.p picture file code }
- {$Iimages.p image processing }
-
- CONST
- EGAint = $10; { EGA video services }
- graymax = 9; { # gray shades - 1 }
-
- TYPE
- crng = 0..graymax; { gray scale index }
- cmaptype = ARRAY[bitrng] OF crng;
-
- VAR
- r : regrec;
- cmap : cmaptype;
-
- {--- Assign EGA colors based on histogram }
-
- PROCEDURE ShadeEGA(pic1 : picptr;
- VAR cmap : cmaptype);
-
- VAR
- bin : bitrng; { index into bins }
- binsum : REAL; { accumulated # pels }
- binthresh : REAL;
- cnum : crng; { color numbers }
- histo : histtype; { intensity histogram }
-
- BEGIN
-
- Writeln('Computing histogram');
- Histogram(pic1,histo); { compute histogram }
- (****
- ShowHist(histo);
- Readln;
- ****)
- {--- first and last colors are each given half a bin }
-
- Writeln('Assigning colors');
-
- binthresh := (maxpel+1.0)*(maxline+1.0)/(graymax+1.0);
- cnum := 0; { start with black... }
- binsum := -(binthresh/2.0); { with 1.5 bins }
- FOR bin := 0 TO maxbit DO BEGIN
- cmap[bin] := cnum; { assign current color }
- binsum := binsum + histo[bin]; { accumulate counts }
- IF binsum >= binthresh { into next color yet? }
- THEN BEGIN { yes, reset accumulator}
- IF cnum < graymax { and tick color number }
- THEN cnum := cnum + 1;
- binsum := binsum - binthresh;
- END;
- END;
-
- END;
-
-
- {--- Show picture on EGA }
- { two EGA pels are used for each image pel to }
- { help aspect ratio and allow gray scale dithering }
-
- PROCEDURE SendEGA(pic : picptr;
- cmap : cmaptype);
-
- VAR
- r : regrec; { BIOS interface regs }
- row,col : INTEGER; { EGA coordinates }
- lndx : linerng; { line number }
- pndx : pelrng; { pel number }
- pelval1 : INTEGER; { pel value left }
- pelval2 : INTEGER; { pel value right }
-
- BEGIN
-
- r.AX := ($00 SHL 8) OR $10; { 640 x 350 / 16 colors }
- Intr(EGAint,r);
-
- row := 50;
- FOR lndx := 0 TO maxline DO BEGIN
- col := 64;
- FOR pndx := 0 TO maxpel DO BEGIN
- CASE cmap[pic^.fmt.lines[lndx].pels[pndx]] OF
- 0 : BEGIN
- pelval1 := 0;
- pelval2 := 0;
- END;
- 1 : BEGIN
- pelval1 := 0;
- pelval2 := 8;
- END;
- 2 : BEGIN
- pelval1 := 8;
- pelval2 := 8;
- END;
- 3 : BEGIN
- pelval1 := 8;
- pelval2 := 7;
- END;
- 4 : BEGIN
- pelval1 := 0;
- pelval2 := 7;
- END;
- 5 : BEGIN
- pelval1 := 7;
- pelval2 := 7;
- END;
- 6 : BEGIN
- pelval1 := 0;
- pelval2 := 15;
- END;
- 7 : BEGIN
- pelval1 := 8;
- pelval2 := 15;
- END;
- 8 : BEGIN
- pelval1 := 7;
- pelval2 := 15;
- END;
- 9: BEGIN
- pelval1 := 15;
- pelval2 := 15;
- END;
- ELSE
- BEGIN
- pelval1 := 14;
- pelval2 := 14;
- END;
- END;
- r.AH := $0C;
- r.AL := pelval1;
- r.BX := $0000;
- r.CX := col;
- r.DX := row;
- Intr(EGAint,r);
- col := Succ(col);
- r.AH := $0C;
- r.AL := pelval2;
- r.BX := $0000;
- r.CX := col;
- r.DX := row;
- Intr(EGAint,r);
- col := Succ(col);
- END;
- row := Succ(row);
- IF KeyPressed
- THEN BEGIN
- TextMode;
- HALT;
- END;
- END;
-
- END;
-
- {--- Main routine }
-
- BEGIN
-
-
- pic1 := NIL; { ensure new alloc }
- PicSetup(pic1); { set up picture array }
-
- filespec := GetFSpec(ParamStr(1));
-
- LoadPicture(filespec,pic1); { read picture }
-
- ShadeEGA(pic1,cmap); { determine color map }
-
- SendEGA(pic1,cmap); { send mapped picture }
-
- GoToXY(1,24);
- Write('Press Enter');
- Readln;
- TextMode;
-
- END.